<template>
    <div class="feeStandard">
        <div class="main">
            <tmpHeader :index='5'/>
            <Row>
                <Col :xs="24">
                    <!-- <div class="margin-up-down">
                        <Button type="primary" @click='modalShow' class="buttonbox">
                            <i class = "iconfont icon-add" style="font-size:14px;margin-right:5px"></i>
                        </Button>
                    </div> -->
                    <div class="margin-up-down">
                        <Select class="w-select" clearable v-model="statustype" placeholder="项目类别">
                            <Option
                                v-for="(item,index) in statusList"
                                :value="item.id"
                                :key="index"
                                style='text-align:center'
                            >{{item.name}}</Option>
                        </Select>
                    </div>
                    <!-- <div class="margin-up-down">
                        <Select v-model="prostatus" clearable style="width:155px" placeholder="请选择项目状态" >
                            <Option v-for="item in projectstatus" :value="item.id" :key="item.id" style='text-align:center'>{{item.name}}</Option>
                        </Select>                                                            
                    </div> -->
                    <div class="margin-up-down">
                        <Input class="w-input" v-model="searchKey" placeholder="项目名称"/>    
                    </div>
                    <div class="margin-up-down">
                        <Button type="primary" @click="searchgetDate(1)">
                            <Icon type="ios-search" size="14"/>
                        </Button>     
                    </div>
                    <div class="margin-up-down">
                        <small style="color:#ff9966;margin-left:20px">
                            备注：本列表数据来源于‘物价收费标准’标识为预约的项目
                        </small>     
                    </div>
                </Col>
            </Row>
            <Table stripe :columns="columns1" :data="data1"></Table>
            <div class="page">
                <Page :total="total" :current='pageNo' :pageSize="pageSize" show-total show-elevator @on-change="pageChange"/>
            </div>
            <Modal
                v-model = "modalStatus"
                width='1100'
                :closable='false'
                :mask-closable="false"
                footer-hide >
                <h2 style='text-align:center;border-bottom:1px solid #ccc;line-height:50px;font-weight:700'>预约项目{{ ModalTitle }}</h2><br>
                <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="85" label-position="left">
                    <Row class="infobox" >
                        <p class="title">项目基本信息</p>
                        <div class="tit">
                            <Col span="8">
                                <FormItem prop="projectCategory" label="项目类别：">
                                    <Select v-model="formValidate.projectCategory" style='width:85%;' :disabled='bjdisabled'>
                                        <Option style='text-align:center;' :value="item.id" v-for='item in projectCategoryList' :key='item.id'>{{item.name}}</Option>
                                    </Select>
                                </FormItem>
                                <FormItem label="项目名称：" prop="name">
                                    <Input v-model="formValidate.name" placeholder="输入项目名称" style='width:85%;' :disabled='bjdisabled'
                                    maxlength="50"></Input>
                                </FormItem>
                                <FormItem prop="chargingUnit" label="项目收费单位：" :label-width="110">
                                    <Select v-model="formValidate.chargingUnit" style='width:84%;' :disabled='bjdisabled'>
                                        <Option style='text-align:center;' :value="item.id" :key='item.id' v-for='item in chargingUnit'>{{ item.name }}</Option>
                                    </Select>
                                </FormItem>
                            </Col>
                            <Col span="8">
                                <FormItem prop="modular" label="业务模块：" class="hongdian">
                                    <!-- 咨询列表 -->
                                    <Select v-model="formValidate.modular" style='width:85%;' :disabled='bjdisabled'>
                                        <Option  style='text-align:center;' :value="item.id" v-for='(item,index) in consultList' :key='index'>{{item.name}}</Option>
                                    </Select>
                                </FormItem>    
                            </Col>
                            <Col span="8">
                                <FormItem prop="deptId" label="所属/执行科室：" :label-width="110">
                                    <Select v-model="formValidate.deptId" style='width:100%;' :disabled='bjdisabled'>
                                        <Option style='text-align:center;' :value="item.id" v-for='item in departmentList' :key='item.id'>{{item.deptNickname}}</Option>
                                    </Select>
                                </FormItem>
                            </Col>
                            <Col span="16">
                                <Row>
                                    <Col span="7">
                                        <FormItem label="启用标识：" :label-width="80">
                                            <iSwitch size="large" v-model="formValidate.status" @on-change="changeStatus(formValidate.status)" :disabled='bjdisabled'>
                                                <span slot="open">开启</span>
                                                <span slot="close">关闭</span>
                                            </iSwitch>                                 
                                        </FormItem>
                                    </Col>
                                    <Col span="8">
                                        <FormItem label="是否为预约项：" :label-width="100">
                                            <iSwitch size="large" v-model="formValidate.isubscribe" @on-change="changeisubscribe(formValidate.isubscribe)" :disabled="isubscribeDisable">
                                                <span slot="open">开启</span>
                                                <span slot="close">关闭</span>
                                            </iSwitch>
                                        </FormItem>
                                    </Col>
                                    <Col span="8">
                                        <FormItem label="患者可否直接预约：" :label-width="120">
                                            <iSwitch size="large" v-model="formValidate.ipatientAppointment" :disabled="ipatientAppointmentDisable">
                                                <span slot="open">开启</span>
                                                <span slot="close">关闭</span>
                                            </iSwitch>
                                        </FormItem>
                                    </Col>
                                </Row>                             
                            </Col>
                            <Col span="8">
                            <FormItem prop="priceBasis" label="项目平台收费标准(元)：" :label-width="157" class="hongdian">
                                    <InputNumber :max="9999" :min="0" v-model="formValidate.priceBasis" placeholder="0.00" style='width:78%;' :disabled='bjdisabled'></InputNumber>
                                </FormItem> 
                            </Col>
                            <Col span="8">
                                <FormItem label="项目收费依据：" prop="chargeBasis" :label-width="105">
                                    <Input v-model="formValidate.chargeBasis" placeholder="输入收费依据" style='width:100%;' maxlength="45" :disabled='bjdisabled'></Input>
                                </FormItem>
                            </Col>
                        </div>
                        
                    </Row>
                    <Row class="infobox">
                        <p class="title">院内系统项目关联</p>
                        <div class="tit">
                            <FormItem label="项目详情：" prop="itemDetails" :label-width="100">
                                <vueEditor
                                    id="editor_id"
                                    v-if="modalStatus"
                                    :textHtml="formValidate.itemDetails"
                                    :urlCode="urlCode"
                                    @valueHandle="afterChange"
                                    :height='100'
                                    style='width:100%;margin:0'
                                ></vueEditor>
                            </FormItem>
                            <FormItem label="项目适用人群：" :label-width="100">
                                <Input v-model="formValidate.suitableCrowd" type="textarea" maxlength="250" :autosize="{minRows: 2,maxRows: 5}" placeholder="请输入适用人群描述"></Input>
                            </FormItem>
                            <FormItem label="项目特点：" :label-width="100">
                                <Input v-model="formValidate.itemFeatures" type="textarea" maxlength="250" :autosize="{minRows: 2,maxRows: 5}" placeholder="请输入项目特点"></Input>
                            </FormItem>
                            <FormItem label="项目预约须知：" :label-width="100">
                                <Input v-model="formValidate.apptNotice" type="textarea" :autosize="{minRows: 2,maxRows: 5}" maxlength="250" placeholder="请输入预约须知"></Input>
                            </FormItem>
                            <Col span="22">
                                <FormItem label="关联HIS项目：" :label-width="100">   
                                    <Table border stripe :columns="columns" :data="data2" ref="table1" style="width: 100%" @on-selection-change="selectChange" >
                                        <template slot="num" slot-scope="props" >
                                            <Input v-model="props.row.num" placeholder="请输入关联数量" type="number" @on-change='money' :disabled='bjdisabled'></Input> 
                                        </template>
                                    </Table><p v-if="this.data2.length" style="border:1px solid #ccc;border-top:none;font-size: 14px; padding-left: 610px; ">总计： <span>{{zj}}元</span></p>       
                                </FormItem>     
                            </Col> 
                            <Col span="2">    
                                <Button type='primary' @click="his" class="hisbutton" v-if='!bjdisabled'>
                                    <i class = "iconfont icon-add" style="font-size:14px;margin-right:5px"></i>
                                </Button> 
                            </Col>
                        </div>                        
                    </Row>    
                </Form>
                <div style='textAlign: center;'>
                    <Button type='primary' @click='handleSubmit("formValidate")' :disabled="isDisable" style="width:95px;height:35px;">
                        <Icon type="ios-checkmark" style="margin-right: 5px" />{{buttonName}}
                    </Button>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <Button @click='handleReset("formValidate")' style="width:75px;height:35px;">
                        <i class = "iconfont icon-butongyi" style="font-size:14px;margin-right:5px"></i>取消
                    </Button>
                </div>
            </Modal>
        </div>
        <!--排班-->
        <Modal
            v-model = "scheduling"
            width='1100'
            :closable='false'
            :mask-closable="false"
            footer-hide>
            <h2 style='text-align:center;border-bottom:1px solid #ccc;line-height:50px;font-weight:700'>项目预约排班</h2>
            <div class="infobox">
                <p class="title">{{proTitle}}</p>
                <Row class="tit">
                    <Col class="text-align-c borderRight" :xs="24" :md="2">
                        <span style="color:red;">*&nbsp;&nbsp;</span>预约类别：
                    </Col>
                    <Col class="padding-l" :xs="24" :md="6">
                        分时段预约
                    </Col>
                    <Col class="text-align-c borderRight" :xs="24" :md="3">
                        <span style="color:red;">*&nbsp;&nbsp;</span>可约周期长度：
                    </Col>
                    <Col class="padding-l" :xs="24" :md="12">
                        <InputNumber min="1" max="99" @on-change="checkInput" v-model="term" style="margin-left: -20px"></InputNumber>&nbsp;&nbsp;&nbsp;&nbsp;天&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                        
                        <small style="color: #ff9966">备注：建议设置7的倍数。</small>
                    </Col>
                </Row>
                <Row class="bordered">
                    <Col :xs="24" :md="2">预约时间：</Col>
                    <Col :xs="24" :md="22">
                        <Row style="text-align: center;">
                            <Col :xs="2">&nbsp;</Col>
                            <Col :xs="3">&nbsp;</Col>
                            <Col :xs="2">星期一</Col>
                            <Col :xs="2">星期二</Col>
                            <Col :xs="2">星期三</Col>
                            <Col :xs="2">星期四</Col>
                            <Col :xs="2">星期五</Col>
                            <Col :xs="2">星期六</Col>
                            <Col :xs="2">星期日</Col>
                        </Row>
                        <Row v-for="(item,index) of upList" :key="index">
                            <Col :xs="2">
                                <span v-if="index+1 == 1">
                                <button class="cus-btn" @click="upAdItem" size="small">+</button>上午
                                </span>
                                <span v-else>&nbsp;</span>
                            </Col>
                            <Col :xs="3">
                                <TimePicker
                                :open="item[8]"
                                :value="item[0]"
                                format="HH:mm"
                                type="timerange"
                                :steps="[1,5]"
                                :clearable="false"
                                :confirm="true"
                                :editable="false"
                                :disabled-hours="[0,1,2,3,4,5,6,7,13,14,15,16,17,18,19,20,21,22,23,24]"
                                @on-change="changeUpTime($event,index)"
                                @on-ok="upOk(index)"
                                >
                                <a href="javascript:void(0)" @click="upClick($event,index)">
                                    <Icon type="ios-clock-outline"></Icon>
                                    <template v-if="item[0][0] === '' || item[0][1] === ''">选择时间段</template>
                                    <template v-else>{{ item[0][0]+'-'+item[0][1] }}</template>
                                </a>
                                </TimePicker>
                            </Col>
                            <Col :xs="2" style="padding-right:50px">
                                <InputNumber min="1" max="99" v-model="item[1]"></InputNumber>
                            </Col>
                            <Col :xs="2" style="padding-right:50px">
                                <InputNumber min="1" max="99" v-model="item[2]"></InputNumber>
                            </Col>
                            <Col :xs="2" style="padding-right:50px">
                                <InputNumber min="1" max="99" v-model="item[3]"></InputNumber>
                            </Col>
                            <Col :xs="2" style="padding-right:50px">
                                <InputNumber min="1" max="99" v-model="item[4]"></InputNumber>
                            </Col>
                            <Col :xs="2">
                                <InputNumber min="1" max="99" v-model="item[5]"></InputNumber>
                            </Col>
                            <Col :xs="2">
                                <InputNumber min="1" max="99" v-model="item[6]"></InputNumber>
                            </Col>
                            <Col :xs="2">
                                <InputNumber min="1" max="99" v-model="item[7]"></InputNumber>
                            </Col>
                            <Col :xs="1">
                                <button
                                v-if="index==upList.length-1 && upList.length!=1"
                                @click="rmUpItem"
                                class="cus-btn"
                                size="small"
                                >-</button>
                            </Col>
                        </Row>
                        <Row v-for="(item,index) of dnList" :key="index">
                            <Col :xs="2">
                                <span v-if="index+1 == 1">
                                <button class="cus-btn" @click="dnAdItem" size="small">+</button>下午
                                </span>
                                <span v-else>&nbsp;</span>
                            </Col>
                            <Col :xs="3">
                                <TimePicker
                                :open="item[8]"
                                :value="item[0]"
                                format="HH:mm"
                                type="timerange"
                                :steps="[1,5]"
                                :clearable="false"
                                :confirm="true"
                                :editable="false"
                                :disabled-hours="[0,1,2,3,4,5,6,7,8,9,10,11,12,18,19,20,21,22,23,24]"
                                @on-change="changeDnTime($event,index)"
                                @on-ok="dnOk(index)"
                                >
                                <a href="javascript:void(0)" @click="dnClick($event,index)">
                                    <Icon type="ios-clock-outline"></Icon>
                                    <template v-if="item[0][0] === '' || item[0][1] === ''">选择时间段</template>
                                    <template v-else>{{ item[0][0]+'-'+item[0][1] }}</template>
                                </a>
                                </TimePicker>
                            </Col>
                            <Col :xs="2">
                                <InputNumber min="1" max="99" v-model="item[1]"></InputNumber>
                            </Col>
                            <Col :xs="2">
                                <InputNumber min="1" max="99" v-model="item[2]"></InputNumber>
                            </Col>
                            <Col :xs="2">
                                <InputNumber min="1" max="99" v-model="item[3]"></InputNumber>
                            </Col>
                            <Col :xs="2">
                                <InputNumber min="1" max="99" v-model="item[4]"></InputNumber>
                            </Col>
                            <Col :xs="2">
                                <InputNumber min="1" max="99" v-model="item[5]"></InputNumber>
                            </Col>
                            <Col :xs="2">
                                <InputNumber min="1" max="99" v-model="item[6]"></InputNumber>
                            </Col>
                            <Col :xs="2">
                                <InputNumber min="1" max="99" v-model="item[7]"></InputNumber>
                            </Col>
                            <Col :xs="1">
                                <button
                                v-if="index==dnList.length-1 && dnList.length!=1"
                                @click="rmDnItem"
                                class="cus-btn"
                                size="small"
                                >-</button>
                            </Col>
                        </Row>
                    </Col>
                </Row>
                <Row class="bordered">
                    <Col class="text-align-c borderRight" :xs="24" :md="2">履约地址：</Col>
                    <Col class="padding-l" :xs="24" :md="17">
                        <Input
                            class="w-input"
                            :maxlength="50"
                            @on-change="checkInput"
                            v-model="address"
                            placeholder="请输入履约时的具体地址"
                        />
                        <span style="color: #ff0000;" v-if="!address">就诊地址不能为空</span>   
                        <!-- addressFlag -->
                    </Col>
                </Row>
                <Row class="bordered">
                    <Col class="text-align-c borderRight" :xs="24" :md="2">备注说明：</Col>
                    <Col class="padding-l" :xs="24" :md="17">
                        <Input class="w-area" v-model="remarks" :maxlength="160" placeholder="请输入备注" />
                    </Col>
                </Row>
                <div class="buttonfoot">
                    <Button type="primary" style="width:75px;height:35px;" @click="sure" :class="{gay:Adisable,green:!Adisable}">
                        <Icon type="ios-checkmark" style="margin-right: 5px" />保存
                    </Button>
                    <Button @click="reback" style="width:75px;height:35px;">
                        <i class = "iconfont icon-butongyi" style="font-size:14px;margin-right:5px"></i> 取消
                    </Button>
                </div> 
            </div>               
        </Modal>
        <Modal @on-ok="submit" v-model="subModal" width='650' title="排班确认" class="okmadal">
            <span>
                排班信息一但保存后，再次修改需要等待本次设置的一个周期过后方可操作，确定提交吗？
            </span>
            <!-- <ul style="display:inline-block;width:48%;vertical-align:middle;text-align:center;">
                <li v-for="(item,index) of upList" :key="index">{{ item[0][0]+'-'+item[0][1] }}</li>
            </ul>
            <ul style="display:inline-block;width:48%;vertical-align:middle;text-align:center;">
                <li v-for="(item,index) of dnList" :key="index">{{ item[0][0]+'-'+item[0][1] }}</li>
            </ul> -->
        </Modal>
        <Modal
            v-model = "modalStatus3"
            width='1000'
            :closable='false'
            :mask-closable="false"
            footer-hide>   
            <h3 style='text-align:center;font-weight:700;margin: 0 10px'>选择HIS收费项目</h3>  
            <div style="display: inline-block;margin: 10px 0 10px 0px;">
                <Select class="w-select" clearable v-model="inspection" style="width:120px;" placeholder="项目分类">
                    <Option
                        v-for="item in projectCategoryList"
                        :value="item.id"
                        :key="item.id"
                        style='text-align:center'
                    >{{item.name}}</Option>
                </Select>
            </div>
            <div style="display: inline-block;margin: 10px 0 10px 10px;">
                <Input
                v-model.trim="xmmc"
                placeholder="请输入项目名称检索"
                style="width: 150px"
                clearable
                />
            </div>
            <div style="display: inline-block;margin: 10px 0 10px 10px;">
                <Button type="primary" icon="ios-search" @click="getHisPage(1)"></Button>
            </div>
            <div style="display: inline-block;margin: 10px 0 10px 10px;float:right">
                <Button type='primary' @click="getSynchronization" disabled='true'>
                    <Icon type="ios-checkmark" style="margin-right: 5px" />同步HIS收费项目
                </Button>           
            </div>
            <Table @on-selection-change="selectChange" :loading="tableLoading" border stripe :columns="columns3" :data="data3" highlight-row ref="table" @on-current-change="handleRowChange"></Table>
            <Page
                :total="count"
                :current="hispageNo"
                :pageSize="hispageSize"
                style="margin-top:10px;text-align:center;"
                @on-change='hispageChange'
            />
            <div style="text-align:center;margin:10px">
                <Button @click="back" >
                    <i class = "iconfont icon-butongyi" style="font-size:14px;margin-right:5px"></i> 返回
                </Button>
            </div>
        </Modal>
    </div>
</template>
<script>
import tmpHeader from "@/pages/organizat/contentmen/tmpHeader";
import vueEditor from "@/components/vueEditor";
import code from "@/configs/base.js";
import api from "@/api/commonApi";
export default {
    components: {
        tmpHeader,
        vueEditor,
    },
    data () {
        const that = this;
        return {
            bjdisabled: false,
            //排班
            id:'',
            term:'1',
            hospitalId: sessionStorage.getItem("hospitalId"),
            isubscribeDisable: false,//禁止预约项点击
            ipatientAppointmentDisable: false,//禁止患者预约项点击
            proTitle:'',
            hosid:'',
            info: {},
            typeList: [{ id: 1, name: "普通门诊" }],
            outpatientType: "普通门诊",
            address: null,
            open: false,
            termRd: false,
            schemaId: null,
            addressFlag: false,
            subModal: false,
            remarks: null,
            upList: [
                [["08:00", "09:00"], null, null, null, null, null, null, null, false],
                [["09:00", "10:00"], null, null, null, null, null, null, null, false],
                [["10:00", "11:00"], null, null, null, null, null, null, null, false],
                [["11:00", "12:00"], null, null, null, null, null, null, null, false]
            ],
            dnList: [
                [["13:00", "14:00"], null, null, null, null, null, null, null, false],
                [["14:00", "15:00"], null, null, null, null, null, null, null, false],
                [["15:00", "16:00"], null, null, null, null, null, null, null, false],
                [["16:00", "17:00"], null, null, null, null, null, null, null, false]
            ],
            //项目添加
            urlCode: '{"urlCode":"' + code.urlCode.richText + '"}',
            isDisable: false,//表单重复提交
            scheduling:false,
            searchKey:'',
            statustype:'',
            statusList: [
                {name:"全部",id:''},
                {name:"检验项目",id:'1'},
                {name:"检查项目",id:'2'},
                {name:"体检项目",id:'3'},
                {name:"手术项目",id:'4'},
                {name:"治疗项目",id:'5'},
                {name:"其他",id:'6'},
            ],
            prostatus:'',
            projectstatus: [
                {name:"全部",id:null},
                {name:"禁用",id:'0'},
                {name:"启用",id:'1'},
            ],
            // 列表数据
            columns1: [
                {
                    key: "sum",
                    title: "排序",
                    align: "center",
                    width:80,
                    render: (h, params) => {
                        let sum = (this.pageNo-1)*this.pageSize + params.index +1;
                        return h("span", sum);
                    }
                },
                {
                    key: "itemType",
                    title: "项目类别",
                    align: "center"
                },
                {
                    key: "itemName",
                    title: "项目名称",
                    align: "center"
                },
                {
                    key: "itemChargeUnitName",
                    title: "单位",
                    align: "center",
                    width:100,
                    render: (h, params) => {
                        this.chargingUnit.forEach(i => {
                            if(i.id == params.row.itemChargeUnit){
                                params.row.itemChargeUnitName = i.name
                            }
                        })
                        return params.row.itemChargeUnitName;
                    }
                },
                {
                    key: "itemUnitPrice",
                    title: "收费单价(元)",
                    align: "center",
                },
                {
                    key: "businessType",
                    title: "业务模块",
                    align: "center",
                    render: (h, params) => {
                        let status = params.row.businessType;
                        let statusText;
                        switch (status) {
                            case 1:
                                statusText = "通用";
                                break;
                            case 2:
                                statusText = "门诊预约";
                                break;
                            case 3:
                                 statusText = "住院复查";
                                break;
                        }
                        return h("span", {}, statusText);
                    }
                },
                {
                    key: "deptName",
                    title: "所属/执行科室",
                    align: "center"
                },
                {
                    key: "itemUsed",
                    title: "是否已排班",
                    align: "center",
                    width:100,
                },
                {
                    key: "curStatus",
                    title: "启用标识",
                    align: "center",
                    width:100,                
                },
                {
                    title: "设置",
                    align: "center",
                    width:180,
                    render:(h,params) => {
                        let row = params.row;
                        return [
                            h('span', {
                                style: {
                                    color: " #5362e1",
                                    width: "60px",
                                    marginRight: '5px'
                                },
                                on: {
                                    click: () => {
                                        this.info = {}
                                        this.isDisable = false
                                        this.scheduling = true
                                        this.proTitle = row.itemName
                                        this.schemaId = row.schemaId
                                        this.pbdeptId = row.deptType
                                        this.pid = row.id
                                        this.hosid = row.hospitalId
                                        //清空
                                        this.dept = '';
                                        this.deptId = '';
                                        this.address = '';
                                        this.outpatientType = '';
                                        this.term = '1';
                                        this.remarks = '';
                                        this.id = ''
                                        this.upList = [
                                            [["08:00", "09:00"], null, null, null, null, null, null, null, false],
                                            [["09:00", "10:00"], null, null, null, null, null, null, null, false],
                                            [["10:00", "11:00"], null, null, null, null, null, null, null, false],
                                            [["11:00", "12:00"], null, null, null, null, null, null, null, false]
                                        ],
                                        this.dnList = [
                                            [["13:00", "14:00"], null, null, null, null, null, null, null, false],
                                            [["14:00", "15:00"], null, null, null, null, null, null, null, false],
                                            [["15:00", "16:00"], null, null, null, null, null, null, null, false],
                                            [["16:00", "17:00"], null, null, null, null, null, null, null, false]
                                        ],
                                        this.departmentList.forEach(i => {
                                            if(this.pbdeptId == i.dictName){
                                                this.pbdeptId = i.dictType
                                            }
                                        })
                                        if(row.schemaId){
                                            this.loadingDoctorPage()
                                        }
                                    }
                                }
                            }, '排班'),
                             " | ",
                            h('span', {
                                style: {
                                    color: " #5362e1",
                                    width: "60px",
                                    marginLeft: '5px',
                                    marginRight: '5px'
                                },
                                on: {
                                    click: () => {
                                        this.isDisable = false
                                        this.modalStatus = true
                                        this.buttonName = '确认修改'
                                        this.ModalTitle = '编辑'
                                        this.bjdisabled = true
                                        this.isubscribeDisable = true
                                        this.ipatientAppointmentDisable = true
                                        this.columns = this.columns22
                                        this.$axios.post(api.findAppointmentItemById,{id: row.id}).then(res => {
                                            if(res.data.success) {
                                                let ret = res.data.object;
                                                this.formValidate.name = ret.itemName;
                                                this.formValidate.itemDetails = ret.details
                                                this.formValidate.apptNotice = ret.yyNotice
                                                this.formValidate.chargeBasis = ret.itemChargeBasis
                                                this.formValidate.projectCategory = ret.itemType.toString()
                                                this.formValidate.modular = ret.businessType
                                                this.formValidate.suitableCrowd = ret.suitableCrowd
                                                this.formValidate.priceBasis = ret.itemUnitPrice
                                                this.formValidate.hisItemCodes = ret.hisItemCodes
                                                this.formValidate.itemFeatures = ret.features
                                                this.formValidate.isMedicalTechnology = ret.isMedicalTechnology
                                                this.formValidate.chargingUnit = ret.itemChargeUnit.toString()
                                                this.formValidate.status = Boolean(Number(ret.curStatus))
                                                this.formValidate.isubscribe = Boolean(Number(ret.isUbscribe))
                                                this.formValidate.ipatientAppointment = Boolean(Number(ret.isPatientyy))
                                                if(this.formValidate.status == false ){
                                                    this.formValidate.isubscribe = false
                                                    this.isubscribeDisable = true   
                                                } 
                                                // else {
                                                //     this.isubscribeDisable = false  
                                                // }
                                                if(this.formValidate.isubscribe == false){
                                                    this.formValidate.ipatientAppointment = false
                                                    this.ipatientAppointmentDisable = true   
                                                } 
                                                // else {
                                                //     this.ipatientAppointmentDisable = false 
                                                // }
                                                this.data2 = [];
                                                if(ret.hisItemList!=null){
                                                    ret.hisItemList.forEach(i=>{
                                                        let item = {
                                                            xmmc : i.hisTechnologyName,
                                                            xmbm : i.hisTechnologyCode,
                                                            num: i.num,
                                                            dj: i.dj,
                                                            jldw: i.jldw,
                                                            chargeId:i.chargeId
                                                        };
                                                        this.handleRowChange(item);
                                                    })
                                                }
                                                this.formValidate.deptId = ret.deptId
                                                this.formValidate.deptType = ret.deptType
                                                this.formValidate.id = ret.id
                                            } else {
                                                this.$Message.error("获取项目详情失败")
                                            }
                                        })
                                    }
                                }
                            }, '编辑'),
                            '|',
                            h('span', {
                                style: {
                                    color: " #5362e1",
                                    width: "60px",
                                    marginLeft: '5px'
                                },
                                on:{
                                    click:() => {
                                        this.update(row)
                                    }
                                }
                            }, '更新号源'),
                        ]
                    }
                }
            ],
            data1: [],
            columns2: [
                {
                    key: "sum",
                    title: "排序",
                    align: "center",
                    width:80
                },
                {
                    key: "xmbm",
                    title: "HIS项目编码",
                    align: "center",
         
                },
                {
                    key: "xmmc",
                    title: "HIS项目名称",
                    align: "center",
                  
                },
                {
                    key: "jldw",
                    title: "计量单位",
                    align: "center",
                 
                },
                {
                    key: "dj",
                    title: "单价（元）",
                    align: "center",
                
                },
                {
                    key: "num",
                    title: "关联数量",
                    align: "center",
                    render:(h,params) => {
                        this.data2[params.index] = params.row
                        return [
                            h('div',
                                this.$refs.table1.$scopedSlots.num({
                                    row: params.row,
                                    idx: params.row._index
                                }),
                                1,
                             )
                        ]
                    }
                },
                {
                    key: "del",
                    title: "设置",
                    align: "center",
                    render:(h,params) => {
                        let row = params.row;
                        return [
                            h('Button', {
                                props: {
                                    type: "error",
                                    size: "small"
                                },
                                style: {
                                    margin: "0px 6px"
                                },
                                on: {
                                    click: () => {
                                        this.handleRemove(row);
                                    }
                                }
                            }, "删除")
                        ]
                    }
                },
            ],
            columns22: [
                {
                    key: "sum",
                    title: "排序",
                    align: "center",
                    width:80
                },
                {
                    key: "xmbm",
                    title: "HIS项目编码",
                    align: "center",
         
                },
                {
                    key: "xmmc",
                    title: "HIS项目名称",
                    align: "center",
                  
                },
                {
                    key: "jldw",
                    title: "计量单位",
                    align: "center",
                 
                },
                {
                    key: "dj",
                    title: "单价（元）",
                    align: "center",
                
                },
                {
                    key: "num",
                    title: "关联数量",
                    align: "center",
                    render:(h,params) => {
                        this.data2[params.index] = params.row
                        return [
                            h('div',
                                this.$refs.table1.$scopedSlots.num({
                                    row: params.row,
                                    idx: params.row._index
                                }),
                                1,
                             )
                        ]
                    }
                },
            ],
            data2:[],
            data2Id:{},
            // 分页数据
            count: 10,
            total:0,
            pageNo: 1,
            pageSize: 10,
            hispageNo: 1,
            hispageSize: 10,
            // 弹出窗状态
            modalStatus: false,
            ModalTitle : "新增",
            // 表单验证以及项目详细数据
            formValidate: {
                // 项目类型
                projectCategory: "",
                // 项目名称
                name: "",
                // 项目规格
                norms: "",
                // 物价码
                priceCode: "",
                // 收费依据
                charge: "",
                // 收费单位
                chargingUnit: "",
                // 收费依据
                priceBasis: "",
                //科室id
                deptId:"",
                // 业务模块
                modular: "",
                // 启用标识
                status: false,
                //是否为预约项
                isubscribe: false,
                //患者可否直接预约
                ipatientAppointment: false,
                // 标识Id
                id: "",
                // 医院ID
                hospitalId: sessionStorage.getItem("hospitalId"),
                // 咨询类型
                consult : "",
                // 咨询价格
                consultPrice: "",
                //项目特点
                itemFeatures:"",
                isMedicalTechnology : "",
            },
            ruleValidate: {
                projectCategory: [{ required: true, message: '请选择项目类别', trigger: 'change' }],
                title: [{ required: true, message: '请选择职称', trigger: 'change' }],
                name: [{ required: true, message: '请输入项目名称', trigger: 'blur' }],
                chargingUnit: [{ required: true, message: '请选择收费单位', trigger: 'change' }],
                priceBasis: [{ required: true, message: '请输入收费标准', trigger: 'change', type:'number'}],
                modular: [{ required: true, message: '请选择业务模块', trigger: 'change', type:'number'}],
                deptId:[{ required: true, message: '请选择科室', trigger: 'change'}],
                consult: [{ required: true, message: '请选择咨询类型', trigger: 'change'}],
                consultPrice: [{ required: true, message: '请输入咨询价格', trigger: 'blur'}],
            },
            // 项目类型列表
            projectCategoryList: [
                {name:"检验项目",id:'1'},
                {name:"检查项目",id:'2'},
                {name:"体检项目",id:'3'},
                {name:"手术项目",id:'4'},
                {name:"治疗项目",id:'5'},
                {name:"其他",id:'6'},
            ],
            // 科室列表
            departmentList: [],
            // 收费单位列表
            // chargingUnit: [
            //     { name: "套", id: '1' },
            //     { name: "次", id: '2' },
            //     { name: "项", id: '3' },
            //     { name: "天", id: '4' }
            // ],
            // 业务模块
            modular: [],
            // 咨询列表
            consultList: [
                { name: "通用", id: 1 },
                { name: "门诊预约", id: 2 },
                { name: "住院复查", id: 3 },
            ],
            buttonName: "确认添加",
            pid:'',
            Adisable:false,
            modalStatus3: false,
            inspection: '',
            xmmc: '',
            columns3:[
                {
                    key: "sum",
                    title: "排序",
                    align: "center",
                    width: 80,
                    render: (h, params) => {
                        let sum = (this.hispageNo-1)*this.hispageSize + params.index +1;
                        return h("span", sum);
                    }
                },
                {
                    key: "sflb",
                    title: "收费类别",
                    align: "center",
                   
                },
                {
                    key: "xmbm",
                    title: "项目编码",
                    align: "center",
                   
                },
                {
                    key: "xmmc",
                    title: "项目名称",
                    align: "center",
                   
                },
                {
                    key: "jldw",
                    title: "计量单位",
                    align: "center",
                   
                },
                {
                    key: "dj",
                    title: "单价",
                    align: "center",
                   
                },
                {
                    key: "zxks",
                    title: "执行科室",
                    align: "center",
                   
                },
                {
                    key: "sfdj",
                    title: "收费等级",
                    align: "center",
                   
                },
            ],
            data3:[],
            zj: 0,
        };
    },
    created () {
        let breadList = [
            { path: "/index", title: "首页" },
            {
                path: "/index/operation/mechanism/index",
                title: "机构运营"
            },
            {
                path: "/index/operation/home",
                title: "机构配置管理"
            }
        ];
        this.$emit("changeBreadList", breadList);
    },
    mounted () {
        if(this.formValidate.status == false ){
            this.formValidate.isubscribe = false
            this.isubscribeDisable = true   
        }
        if(this.formValidate.isubscribe == false){
            this.formValidate.ipatientAppointment = false
            this.ipatientAppointmentDisable = true   
        }
        // 页面数据
        this.getdept()
        this.getDate()
        this.getfeeunitenum()
    },
    methods: {
        //更新号源
        update(item) {
            this.$axios.post(api.generateItemResource, {itemId: item.id}).then(res => {
                if (res.data.code == 1) {
                    this.$Message.success(res.data.message);
                } else {
                    this.$Message.error(res.data.message);
                }
            });
        },
         // 加载收费列表
        getfeeunitenum(){
              this.$axios.post(api.findFeeEnum,{}).then(resp => {
                if(resp.data.success) {
                    let ret = resp.data;
                    this.chargingUnit = ret.object;
                }
            })
         },
        changeStatus(val){
            if(val == false){
                this.formValidate.isubscribe =  false
                this.formValidate.ipatientAppointment = false
                this.isubscribeDisable = true
                this.ipatientAppointmentDisable = true              
            } else {
                this.isubscribeDisable = false           
            }
        },
        changeisubscribe(val){
            if(val == false){
                this.formValidate.ipatientAppointment = false
                this.ipatientAppointmentDisable = true               
            } else {
                this.ipatientAppointmentDisable = false
            }
        },
        //排班取消
        reback() {
            this.scheduling = false
            this.Adisable = false
        },
        afterChange(val) {
            this.formValidate.itemDetails = val;
        },
        // 分页器改变
        pageChange(index) {
            this.pageNo = index;
            this.getDate();
        },
        // 新增项目
        modalShow () {
            this.isDisable = false
            this.modalStatus = true
            this.bjdisabled = false
            this.columns = this.columns2
            this.changeStatus(false)
            this.ModalTitle = '新增'
            this.buttonName = '确认添加'
            this.formValidate.id = ''
            this.data2 = []
        },
        //获取科室信息
        getdept(){
            this.$axios.post(api.findDeptName, {"hospitalId": this.formValidate.hospitalId,medicalTechnology: 1}).then(res => {
                if (res.data.code === 1) {
                    this.departmentList = res.data.object;
                } else {
                    this.$Message.error(res.data.message);
                }
            });
        },
        //添加HIS项目
        his(){
            this.modalStatus3 = true
            this.getHisPage(this.hispageNo)
        },
        //获取HIS收费项目
        getHisPage(hispageNo){
            let params = {
                "hospitalId": this.formValidate.hospitalId,
                "pageNo": hispageNo,
                "pageSize": this.hispageSize,   
                "inspection": this.inspection ? this.inspection : '',                  
            }
            if (this.xmmc != "") {
                params.xmmc = this.xmmc.trim();
            }
            this.$axios
                .post(api.findHisProjectPage, params)
                .then(resp => {
                    console.log("入参",params)                   
                    this.count = resp.data.object.total;
                    let ret = resp.data.object;
                    if(resp.data.object.records){
                        this.data3 = ret.records
                        ret.records.forEach((item,index) => {
                            // 排序
                            item.sum = this.addZeros(index)
                        })                          
                    } else {
                        this.data3 = []
                    }  
                    console.log("回参 ",ret)                  
                })
                .catch(err => {
                    console.log(err);
                });
        },
        //同步机构his项目信息
        getSynchronization(){
            let params = {
                "hospitalId": this.formValidate.hospitalId,
                "pageNo": this.hispageNo,
                "pageSize": this.hispageSize,   
                "inspection": this.inspection,                
                "moldType": 0   
            }
            if (this.xmmc != "") {
                params.xmmc = this.xmmc.trim();
            }
            this.$axios
                .post(api.synHisProject, params)
                .then(resp => {
                    let ret = resp.data.object;
                    this.$Message.success('同步成功')
                })
                .catch(err => {
                    console.log(err);
                });
        },
         //表格
        selectChange(selections) {
            this.selections = selections;
        },
        //选择his收费项目
        handleRowChange(currentRow, oldCurrentRow){
            if(!currentRow.num){
                currentRow.num= 1
            }        
            // this.data2.push(currentRow) 
            // this.data2.forEach((item,index) => {
            //     // 排序
            //     item.sum = this.addZeros(index)
            //     if(item.num){
            //         this.money()
            //     }
            // })
            if(this.data2Id[currentRow.ybxmbm]) {
                this.$Message.error('该收费项已添加，请勿重复添加')
            } else {
                this.data2.push(currentRow);
                this.data2Id[currentRow.ybxmbm] = currentRow.ybxmbm;
                this.data2.forEach((item,index) => {
                    item.sum = this.addZeros(index)
                    if(item.num){
                        this.money()
                    }
                })
            }
        },
        //计算总价
        money(){
            this.zj = 0
            if (this.data2 && this.data2.length) {               
                this.data2.map(item => {  
                    if(item.num){
                        this.zj += Number(item.dj)*Number(item.num);
                    }                
                    
                })
            }        
        },
        //删除选择的HIS收费项目
        handleRemove(val){
            this.data2.forEach((i,index) =>{
                if(index == val._index){
                    this.data2.splice(val._index, 1)
                    this.data2Id[i.ybxmbm] = ''
                }
            })   
            console.log(this.data2Id)   
            //计算总价
            this.money()
        },
        //弹窗返回
        back(){
            this.modalStatus3 = false
            this.inspection = ''
            this.xmmc = ''
        },
        // 保存修改
        handleSubmit (name) {
            this.isDisable = true
            this.$refs[name].validate((valid) => {
                if (valid) {
                    if(String(this.formValidate.priceBasis).indexOf('.')!=-1 && String(this.formValidate.priceBasis).split('.')[1].length>2){
                        this.$Message.error('项目平台收费标准请保留两位小数!');
                        this.isDisable = false  //放开点击了
                        return;
                    }
                    if(this.formValidate.itemDetails.length > 2000) {
                        this.$Message.error('项目详情超出最大限制2000字');
                        this.isDisable = false  //放开点击了
                        return;
                    }
                    let url = api.saveAppointmentItem;
                    let params = {
                        "hospitalId": this.formValidate.hospitalId,
                        "deptId":this.formValidate.deptId,//科室id
                        "itemName": this.formValidate.name,//项目名称
                        "itemType": this.formValidate.projectCategory,//项目分类
                        "hisItemCodes":this.formValidate.hisItemCodes,//HIS项目编码
                        "itemUnitPrice":this.formValidate.priceBasis,//收费单价
                        "suitableCrowd":this.formValidate.suitableCrowd,//适用人群
                        "yyNotice":this.formValidate.apptNotice,//预约须知
                        "details":this.formValidate.itemDetails,//项目详情
                        "curStatus": Number(this.formValidate.status),//是否启用
                        "isUbscribe": Number(this.formValidate.isubscribe),//是否为预约项
                        "isPatientyy": Number(this.formValidate.ipatientAppointment),//是否患者可否直接预约
                        "businessType":String(this.formValidate.modular),//业务模块
                        "itemChargeBasis":this.formValidate.chargeBasis,//收费依据
                        "itemChargeUnit":this.formValidate.chargingUnit,//收费单位
                        "features":this.formValidate.itemFeatures,//项目特点
                    }
                    this.departmentList.forEach(z => {
                        if(z.id == this.formValidate.deptId){
                            params.deptName = z.deptNickname
                            params.deptType = z.dictType
                        }
                    })    
                    this.chargingUnit.forEach(s => {
                        if(Number(this.formValidate.chargingUnit) == Number(s.id)) {
                            params.itemChargeUnitName = s.name
                        }
                    })
                    let hisItemList = 
                        this.data2.map(i=>({
                            hisTechnologyName : i.xmmc,
                            hisTechnologyCode : i.xmbm,
                            num: Number(i.num),
                            dj: i.dj,
                            jldw: i.jldw,
                            chargeId:i.chargeId
                        }))                  
                    params.hisItemList =  hisItemList 
                    if(Boolean(this.formValidate.id)) {
                        params.id = this.formValidate.id
                        url = api.saveAppointmentItem
                    }
                    this.$axios.post(url, params).then(res => {
                        if(res.data.success) {
                            this.$Message.success('保存成功')
                            // 重新加载列表
                            this.getDate();
                            this.isDisable = false;//放开点击了
                            // 弹窗数据初始化
                            this.handleReset('formValidate');
                            this.modalStatus = false;
                        } else {
                            this.isDisable = false;//放开点击了
                            this.$Message.error(res.data.message)
                        }
                    }).catch(err => {
                        this.isDisable = false;//放开点击了
                        console.log(err);
                    });
                } else {
                    this.$Message.error('请完整填写必填项!');
                    this.isDisable = false  //不可点击
                }
            })
        },
        // 取消保存
        handleReset (name) {
            this.modalStatus = false
            this.$refs[name].resetFields();
            this.buttonName = '确认添加'
            this.formValidate.projectCategory = ''
            this.formValidate.name = ''
            this.formValidate.itemDetails = ''
            this.formValidate.apptNotice = ''
            this.formValidate.chargeBasis = ''
            this.formValidate.projectCategory =''
            this.formValidate.suitableCrowd =''
            this.formValidate.priceBasis = ''
            this.formValidate.hisItemCodes = ''
            this.formValidate.itemFeatures = ''
            this.formValidate.status = false
            this.formValidate.isubscribe = false
            this.formValidate.ipatientAppointment = false
            this.formValidate.businessType = ''
            this.data2Id = {}
        },
        searchgetDate() {
            this.pageNo = 1
            this.getDate ()
        },
        // 加载列表数据
        getDate () {
            this.isDisable = false
            let params  
                params = {
                    hospitalId: this.hospitalId,        
                    itemName: this.searchKey,
                    itemType:this.statustype,
                    curStatus:this.prostatus,
                    isUbscribe: 1,
                    "pageNo": this.pageNo,
                    "pageSize": this.pageSize
                }        
            let url = api.findAppointmentItemList
            this.$axios.post(url, params).then(res => {
                if (res.data.success) {
                    let ret = res.data.object;
                    this.total = ret.total
                    if(ret.records){
                        ret.records.forEach((item,index) => {
                            // 排序
                            item.sum = this.addZeros(index)
                            // 项目类型                           
                            if(this.projectCategoryList) {
                                this.projectCategoryList.forEach(i => {
                                    if(Number(item.itemType) == Number(i.id)) {
                                        item.itemType = i.name
                                    }
                                })
                            }
                            // 收费单位 列表 
                            if(this.chargingUnit) {
                                this.chargingUnit.forEach(s => {
                                    if(Number(item.itemFeeUnit) == Number(s.id)) {
                                        item.itemFeeUnit = s.name
                                    }
                                })
                            }                          
                            item.curStatus = item.curStatus == 0 ? "禁用" : "启用"
                            if(item.schemaId) {
                                item.itemUsed = '是'
                            } else {
                                item.itemUsed = '否'
                            }
                        })
                        this.data1 = ret.records
                    } else {
                        this.data1 = []
                    }  
                } 
            })
        },
        closeTimePicker() {
            this.upList.map((el, i) => {
                el[8] = false;
            });
            this.dnList.map((el, i) => {
                el[8] = false;
            });
            this.$forceUpdate();
            },
        upAdItem() {
            let time = this.upList[this.upList.length - 1][0][1].toString();
            let status = time < "12:00"; //js 里面 date类型 11:00 比 12:00 大
            if (status) {
                let sliceh = parseInt(time.slice(0, 2));
                let afterh = sliceh + 1;
                let slicem = time.slice(3);
                slicem = afterh >= 12 ? "00" : slicem;
                afterh = afterh < 10 ? "0" + afterh : afterh > 12 ? "12" : afterh;
                let tmph = afterh + ":" + slicem;
                let tmpItem = [[time, tmph], null, null, null, null, null, null, null];
                this.upList.push(tmpItem);
            } else {
                this.infoMsg("上午的结束时间不能超过12:00,请先调整时间段时间再添加");
            }
            },
        dnAdItem() {
            let time = this.dnList[this.dnList.length - 1][0][1].toString();
            let status = time < "17:00"; //js 里面 date类型 11:00 比 12:00 大
            if (status) {
                let sliceh = parseInt(time.slice(0, 2));
                let afterh = sliceh + 1;
                let slicem = time.slice(3);
                slicem = afterh >= 17 ? "00" : slicem;
                afterh = afterh < 10 ? "0" + afterh : afterh > 17 ? "17" : afterh;
                let tmph = afterh + ":" + slicem;
                let tmpItem = [[time, tmph], null, null, null, null, null, null, null];
                this.dnList.push(tmpItem);
            } else {
                this.infoMsg("下午的结束时间不能超过17:00,请先调整时间段时间再添加");
            }
        },
        rmUpItem() {
            this.upList.pop();
        },
        rmDnItem() {
            this.dnList.pop();
        },
        backTime(minTime, maxTime, startTime, endTime) {
            let min = startTime,
                max = endTime;
            let tmpMinArr = minTime.split(":");
            let tmpMaxArr = maxTime.split(":");
            let tmpStartArr = startTime.split(":");
            if (min <= minTime) {
                min = minTime;
                if (max <= minTime) {
                tmpMinArr[1] = parseInt(tmpMinArr[1]) + 5;
                tmpMinArr[0] =
                    tmpMinArr[1] > 55
                    ? parseInt(tmpMinArr[0]) + 1
                    : parseInt(tmpMinArr[0]);
                tmpMinArr[0] = tmpMinArr[0] < 10 ? "0" + tmpMinArr[0] : tmpMinArr[0];
                tmpMinArr[1] = tmpMinArr[1] > 55 ? 0 : tmpMinArr[1];
                tmpMinArr[1] = tmpMinArr[1] < 10 ? "0" + tmpMinArr[1] : tmpMinArr[1];
                max = tmpMinArr[0] + ":" + tmpMinArr[1];
                }
            }
            if (max >= maxTime) {
                max = maxTime;
                if (min >= maxTime) {
                tmpMaxArr[1] = parseInt(tmpMaxArr[1]) - 5;
                tmpMaxArr[0] =
                    tmpMaxArr[1] < 0
                    ? parseInt(tmpMaxArr[0]) - 1
                    : parseInt(tmpMaxArr[0]);
                tmpMaxArr[0] = tmpMaxArr[0] < 10 ? "0" + tmpMaxArr[0] : tmpMaxArr[0];
                tmpMaxArr[1] = tmpMaxArr[1] < 0 ? 55 : tmpMaxArr[1];
                tmpMaxArr[1] = tmpMaxArr[1] < 10 ? "0" + tmpMaxArr[1] : tmpMaxArr[1];
                min = tmpMaxArr[0] + ":" + tmpMaxArr[1];
                }
            }
            if (min == max) {
                let minute1 = parseInt(tmpStartArr[1]) + 5;
                tmpStartArr[0] =
                minute1 > 55
                    ? parseInt(tmpStartArr[0]) + 1
                    : parseInt(tmpStartArr[0]);
                tmpStartArr[0] =
                tmpStartArr[0] < 10 ? "0" + tmpStartArr[0] : tmpStartArr[0];
                minute1 = minute1 < 10 ? "0" + minute1 : minute1 > 55 ? "00" : minute1;
                max = tmpStartArr[0] + ":" + minute1;
            }
            return [min, max];
            },
        changeUpTime(time, index) {
            if (index > 0) {
                //非第一行
                if (index < this.upList.length - 1) {
                //中间的
                let prev = this.upList[index - 1][0][1]; //最低时间
                let next = this.upList[index + 1][0][0]; //最高时间
                time = this.backTime(prev, next, time[0], time[1]);
                } else {
                //最后一行
                let prev = this.upList[index - 1][0][1]; //最小时间
                let next = "12:00";
                time = this.backTime(prev, next, time[0], time[1]);
                }
            } else {
                //第一行
                if (this.upList.length > 1) {
                //多行第一行
                let nextTime = this.upList[index + 1][0][0]; //最高时间
                let prev = "08:00";
                time = this.backTime(prev, nextTime, time[0], time[1]);
                } else {
                //就剩一行
                let prev = "08:00";
                let next = "12:00";
                time = this.backTime(prev, next, time[0], time[1]);
                }
            }
            this.upList[index][0] = time;
            this.$forceUpdate();
        },
        upClick(e, index) {
            e.stopPropagation();
            this.closeTimePicker();
            this.upList[index][8] = true;
            this.$forceUpdate();
            },
        upOk(index) {
            this.upList[index][8] = false;
            this.$forceUpdate();
        },
        infoMsg(msg) {
            this.$Message.info({ content: msg, duration: 5 });
        },
        errMsg(msg) {
            this.$Message.error({ content: msg, duration: 5 });
        },
        // 加载医生分时段信息
        loadingDoctorPage(){
            let data = {}
            this.$axios.post(api.findAppointmentSchemaById,{id: this.schemaId}).then(resp => {
            this.info = resp.data.object;
            this.info.createTime = this.info.createTime.slice(0,10);
            let after = this.getNewData(this.info.createTime,this.info.term)
            let today = this.GetDate(0)
            console.log('周期最后天',after,'今天',today)
            if(after>today){
                this.Adisable = true
            }else{
                this.Adisable = false
            }
            let day;
            let arr = []
            let bigarr = []
            console.log(this.info)
            this.info.details.map((el, i) => {
                // if (el.startTime == '08:00' && el.endTime == '09:00'|| el.startTime == '09:00' && el.endTime == '10:00'|| el.startTime == '10:00' && el.endTime == '11:00'||el.startTime == '11:00' && el.endTime == '12:00') {
                //     day = '1'
                // }
                if ( el.endTime == '09:00'||  el.endTime == '10:00'|| el.endTime == '11:00'|| el.endTime == '12:00') {
                    day = '1'
                }else{
                    day = '2'
                }
                arr.push({'day':day})
                if (day == 1) {
                    this.upList = [];
                    return;
                } else if (day == 2) {
                    this.dnList = [];
                    return;
                }
            });
            var list = this.info.details.map((key,index) => { return {...key,...arr[index]}})
            console.log('ss',list)
            list.map((el, i) => {
                if(el.day==1){
                    let tmpPiece = [el.startTime, el.endTime];
                    if (this.upList.length <= 0) {
                        let tmpArr = [
                            tmpPiece,
                            null,
                            null,
                            null,
                            null,
                            null,
                            null,
                            null
                        ];
                        tmpArr[1] = el.monNumber;
                        tmpArr[2] = el.tueNumber;
                        tmpArr[3] = el.wedNumber;
                        tmpArr[4] = el.thuNumber;
                        tmpArr[5] = el.friNumber;
                        tmpArr[6] = el.satNumber;
                        tmpArr[7] = el.sunNumber;
                        tmpArr.id = el.id;
                        this.upList.push(tmpArr);
                    } else {
                        let pFlag = true;
                        let tmpIndex = null;
                        let tmpArr = [
                            tmpPiece,
                            null,
                            null,
                            null,
                            null,
                            null,
                            null,
                            null
                        ];
                        this.upList.map((ele, i) => {
                            if (ele[0].toString() === tmpPiece.toString()) {
                                pFlag = false;
                                tmpIndex = i;
                            }
                        });
                        if (pFlag) {
                            tmpArr[1] = el.monNumber;
                            tmpArr[2] = el.tueNumber;
                            tmpArr[3] = el.wedNumber;
                            tmpArr[4] = el.thuNumber;
                            tmpArr[5] = el.friNumber;
                            tmpArr[6] = el.satNumber;
                            tmpArr[7] = el.sunNumber;
                            tmpArr.id = el.id;
                            this.upList.push(tmpArr);
                        } else {
                            this.upList[tmpIndex][el.week] = el.num;
                        }
                    }
                }else if(el.day == 2) {
                    let tmpPiece = [el.startTime, el.endTime];
                    if (this.dnList.length <= 0) {
                        let tmpArr = [
                            tmpPiece,
                            null,
                            null,
                            null,
                            null,
                            null,
                            null,
                            null
                        ];
                        tmpArr[1] = el.monNumber;
                        tmpArr[2] = el.tueNumber;
                        tmpArr[3] = el.wedNumber;
                        tmpArr[4] = el.thuNumber;
                        tmpArr[5] = el.friNumber;
                        tmpArr[6] = el.satNumber;
                        tmpArr[7] = el.sunNumber;
                        tmpArr.id = el.id;
                        this.dnList.push(tmpArr);
                    } else {
                        let pFlag = true;
                        let tmpIndex = null;
                        let tmpArr = [
                            tmpPiece,
                            null,
                            null,
                            null,
                            null,
                            null,
                            null,
                            null
                        ];
                        this.dnList.map((ele, i) => {
                        if (ele[0].toString() === tmpPiece.toString()) {
                            pFlag = false;
                            tmpIndex = i;
                        }
                        });
                        if (pFlag) {
                            tmpArr[1] = el.monNumber;
                            tmpArr[2] = el.tueNumber;
                            tmpArr[3] = el.wedNumber;
                            tmpArr[4] = el.thuNumber;
                            tmpArr[5] = el.friNumber;
                            tmpArr[6] = el.satNumber;
                            tmpArr[7] = el.sunNumber;
                            tmpArr.id = el.id;
                            this.dnList.push(tmpArr);
                        } else {
                            this.dnList[tmpIndex][el.week] = el.num;
                        }
                    }
                }
            });
            this.dept = this.info.dept;
            this.deptId = this.info.deptId;
            this.address = this.info.address;
            this.outpatientType = this.info.outpatientType;
            this.term = this.info.term;
            this.remarks = this.info.remarks;
            this.id = this.info.id
        }).catch(err => {
                // this.$Message.info("服务器超时，请重新访问");
            });
        },
        changeDnTime(time, index) {
            if (index > 0) {
                //非第一行
                if (index < this.dnList.length - 1) {
                    //中间的
                    let prev = this.dnList[index - 1][0][1];
                    let next = this.dnList[index + 1][0][0];
                    time = this.backTime(prev, next, time[0], time[1]);
                } else {
                    //最后一行
                    let prev = this.dnList[index - 1][0][1];
                    let next = "17:00";
                    time = this.backTime(prev, next, time[0], time[1]);
                }
            } else {
                //第一行
                if (this.dnList.length > 1) {
                    let prev = "13:00";
                    let nextTime = this.dnList[index + 1][0][0];
                    time = this.backTime(prev, nextTime, time[0], time[1]);
                } else {
                    let prev = "13:00";
                    let next = "17:00";
                    time = this.backTime(prev, next, time[0], time[1]);
                }
            }
            this.dnList[index][0] = time;
            this.$forceUpdate();
        },
        dnClick(e, index) {
            e.stopPropagation();
            this.closeTimePicker();
            this.dnList[index][8] = true;
            this.$forceUpdate();
        },
        dnOk(index) {
            this.dnList[index][8] = false;
            this.$forceUpdate();
        },
        sure() {
            if(this.Adisable){
                this.$Message.info("设置的周期尚未到期不可修改");
                return
            }else{
                this.subModal = true;
                setTimeout(() => {
                
                }, 1000);
            }
        },
        submit(){
            this.inserDoctorData();
        },
        // 添加医生排班
        inserDoctorData() {
            let flag = true;
            if (this.term == null) return (this.termRd = true);
            let tmpRegistertimes = [];
            console.log('打印',this.upList)
            this.upList.map((el, i) => {
                let tmpObj = {};
                for (let i = 1; i <= 7; i++) {
                    if (el[i] != "" && el[i] > 0) {
                        tmpObj.startTime = el[0][0];
                        tmpObj.endTime = el[0][1];
                    }
                }
                tmpObj.id = el.id
                tmpObj.monNumber = el[1];
                tmpObj.tueNumber = el[2];
                tmpObj.wedNumber = el[3];
                tmpObj.thuNumber = el[4];
                tmpObj.friNumber = el[5];
                tmpObj.satNumber = el[6];
                tmpObj.sunNumber = el[7];
                if( el[1]!=null ||  el[2]!=null ||  el[3]!=null ||  el[4]!=null ||  el[5]!=null ||  el[6]!=null ||  el[7]!=null){
                    tmpRegistertimes.push(tmpObj);
                }
            });
            this.dnList.map((el, i) => {
                let tmpObjb = {};
                for (let i = 1; i <= 7; i++) {
                    if (el[i] != "" && el[i] > 0) {
                        tmpObjb.startTime = el[0][0];
                        tmpObjb.endTime = el[0][1];
                    }
                }
                tmpObjb.id = el.id
                tmpObjb.monNumber = el[1];
                tmpObjb.tueNumber = el[2];
                tmpObjb.wedNumber = el[3];
                tmpObjb.thuNumber = el[4];
                tmpObjb.friNumber = el[5];
                tmpObjb.satNumber = el[6];
                tmpObjb.sunNumber = el[7];
                if( el[1]!=null ||  el[2]!=null ||  el[3]!=null ||  el[4]!=null ||  el[5]!=null ||  el[6]!=null ||  el[7]!=null){
                    tmpRegistertimes.push(tmpObjb);
                }
            });
            console.log(tmpRegistertimes)
            if (!this.address) {
                this.addressFlag = true;
                flag = false;
            }
            if (tmpRegistertimes.length <= 0) {
                flag = false;
                this.$Message.error({
                content: "请至少有一个号源有号再保存，谢谢",
                duration: 5
                });
            }
            if (flag) {
                this.addressFlag = false;
                let params = {};
                params.address = this.address;
                params.hospitalId = this.hosid;
                params.id = this.id;
                params.remarks = this.remarks;
                params.term = this.term;
                params.itemId = this.pid;
                params.deptType = this.pbdeptId;
                params.details = tmpRegistertimes;
                params.details.schemaId = this.id;
                let url = "";
                let msg = "";
                if (this.id) {
                    url = api.updateAppointmentSchema;
                    msg = "修改";
                } else {
                    url = api.insertAppointmentSchema;
                    msg = "添加";
                }
                console.log("预约项目排班", params);
                this.$axios.post(url, params).then(resp => {
                    if (resp.data.success) {
                        this.$Message.info(msg + "成功");
                        this.getDate();
                        this.subModal = false;
                        this.scheduling = false
                        this.Adisable = false
                    } else {
                        this.$Message.info(msg + "失败，请重试");
                    }
                }).catch(err => {
                    console.log(err);
                });
            }
        },
        // 分页器改变
        hispageChange(index) {
            this.hispageNo = index;
            if (this.Name) {
                this.getHisPage(index, this.Name);
            } else {
                this.getHisPage(index);
            }
        },
    },
    watch: {
        formValidate: {
            handler(n) {
            },
            deep: true
        }
    }
};
</script>
<style lang="less" scoped>
.cus-btn {
    vertical-align: middle;
    width: 30px;
    height: 30px;
    line-height: 30px;
    color: #ffffff;
    font-size: 30px;
    border: 0;
    border-radius: 50%;
    background: #5362e1;
    margin: 0 10px;
    &:focus {
    border: 0;
    outline: none;
    }
}
.gay{
    color: #666;
    background: #f5f5f5;
    border:1px solid #999;
}
.green{
    color: #fff;
    background: #5362e1;
}
.feeStandard {
    width: calc(100%);
    padding: 10px 30px;
    margin: 0 auto;
    background: #fff;
    box-sizing: border-box;
    .padding-l {
        padding-left: 5px;
    }
    .borderRight {
        border-right: 1px solid #e5e5e5;
    }
    .w-select {
        width: 100px;
    }
    .w-input {
        width: 100%;
    }
    .text-align-c {
        text-align: center;
        line-height: 32px;
    }
    .w-area {
        width: 100%;
    }
    span.rdColor {
        color: #ff0000;
    }
    .margin-up-down {
        display: inline-block;
        margin: 10px 0;
    }
    .page{
      text-align: center;
      margin: 20px 0;
    }
    .buttonbox{
        background-color: #21c780;
        border: 1px solid #21c780;
    }
    .main {
        display: flex;
        flex-direction: column;
    }
}
.infobox {
    border: 1px solid #f0f0f0;
    box-shadow: 0 4px 3px #ebedf8;
    border-radius: 5px;
    margin: 20px 0;
    .hongdian{
        margin-left: -11px;
    }
    .title {
        font-size: 20px;
        padding-left: 15px;
        margin-bottom: 20px;
        color: #333;
        height: 40px;
        line-height: 40px;
        background: #ebedf8;         
    }
    .tit{
        margin: 0 20px;
    }    
    .bordered {
        margin-left: 30px;
        margin-top: 20px;
    }
    .buttonfoot{
        text-align: center;
        width:100%;
        margin: 20px 0;
    }
    .hisbutton{
       float:right;
    }
}
/deep/ .ivu-modal-wrap {
    .ivu-modal{
        float:right !important;
        background-color: #fff;
        border-radius: 10px;
        top: 0px;
        height: 100%;
    }
}
 /deep/ .okmadal {
    float:none !important;
    background-color: #fff;
    border-radius: 10px;
    top: 100px;
}
</style>
